package service;

import java.util.ArrayList;
import java.util.Set;

import dao.WordDAO;
import entitys.Word;

public class WordService {

	private WordDAO wd = new WordDAO();

	public void addWord(Word word) {
		Word w = null;

		w = wd.findByValue(word.getValue());

		if (w != null) {
			int count = 0;
			count += word.getCount();
			count += w.getCount();
			w.setCount(count);
			wd.updateCount(w);
		}
		else{wd.add(word);}		
	}
	
	
	public ArrayList<Word> valueTranslation(){
		return wd.getNumberOfRows();
	}

	public Set<Word> getAll() {
		return wd.getAll();
	}

	public Word findByValue(String val) {
		return wd.findByValue(val);
	}

}
